package com.machine.tag;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.machine.bean.BetterSupportBean;
import com.machine.dao.search.SearchDao;

public class IndexTag extends SimpleTagSupport {

	@Override
	public void doTag() throws JspException, IOException {
		PageContext pageContext = (PageContext) this.getJspContext();
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
//		HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
		
		WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
		SearchDao searchDao = (SearchDao) wac.getBean("SearchDao");
		
		List<BetterSupportBean> list = searchDao.getBetterSupport();
		
		
		request.setAttribute("better", list);
		request.setAttribute("ads", searchDao.getAds());
		request.setAttribute("recommended", searchDao.getrecommended());
		request.setAttribute("latestSearch", searchDao.getLatestSearch());
		request.setAttribute("publishers", searchDao.getPublisher());
		request.setAttribute("endMes", searchDao.getEnd());
		request.setAttribute("map", searchDao.getAllKinds());
	}
	
	
	
}
